package com.ygh.controller;
import com.ygh.pojo.VipUser;
import com.ygh.service.VipUserService;
import com.ygh.vo.PageResult;
import com.ygh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/vipuser")
public class VipUserController{
    @Autowired
    private VipUserService vipUserService;
    @PostMapping("/login")
    public SysResult getVipUser(@RequestBody VipUser vipUser){
        String token=vipUserService.getVipUser(vipUser);
        if(StringUtils.hasLength(token)){
            return SysResult.success(token);
        }
        return SysResult.fail();
    }
    @PostMapping("/addvipuser")
    public SysResult addVipUser(@RequestBody VipUser vipUser){
        Integer count=vipUserService.addVipUser(vipUser);
        if(count==1){
            return SysResult.fail();
        }
        return SysResult.success();
    }
    @GetMapping("/getVipUser")
    public SysResult getVipUser(PageResult pageResult){
        pageResult=vipUserService.getvipuser(pageResult);
        return SysResult.success(pageResult);
    }
    @DeleteMapping("/deleteUser/{carId}")
    public SysResult deleteUser (@PathVariable String carId){
        vipUserService.deleteUserByCarId(carId);
        return SysResult.success();
    }
    @PutMapping("/updateVipUser")
    public SysResult updateVipUser(@RequestBody VipUser vipUser){
        vipUserService.updateVipUser(vipUser);
        return SysResult.success();
    }



}
